package com.zzyl.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author :下次
 * @date : 2024/5/13, 8:53
 * Description:
 */
@Service
@Slf4j
public class NursingLevelServiceImpl implements NursingLevelService {

    @Autowired
    NursingLevelMapper nursingLevelMapper;

    @Override
    public List<NursingLevelVo> nursingLevelList() {
        log.info("查询所有护理等级");
        return nursingLevelMapper.gteNursingLevelList();
    }

    @Override
    public PageResponse<NursingLevelVo> selectByPage(Integer pageNum, Integer pageSize, String name, Integer status) {
        log.info("分页查询:{}", name);
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingLevelVo> page = nursingLevelMapper.selectByPage(name, status);
        PageResponse<NursingLevelVo> pageResponse = PageResponse.of(page, NursingLevelVo.class);

        return pageResponse;
    }

    @Override
    public void addNursingLevelDto(NursingLevelDto nursingLevelDto) {

        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        log.info("新增 nursingLevel:{}", nursingLevel);
        nursingLevelMapper.addNursingLevelDto(nursingLevel);
    }

    @Override
    public NursingLevelVo getNursingLevelById(Long id) {

        log.info("回显id:{}", id);
        return nursingLevelMapper.getNursingLevelById(id);
    }

    @Override
    public void updateNursingLevelDto(NursingLevelDto nursingLevelDto) {
        log.info("修改:{}", nursingLevelDto);
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.updateNursingLevelDto(nursingLevel);


    }

    @Override
    public void updateNursingLevelStatus(Long id, Integer status) {
        log.info("修改状态:{}", status);
        nursingLevelMapper.updateNursingLevelStatus(id, status);
    }


    @Override
    public void delete(Long id) {
        nursingLevelMapper.delete(id);

    }
}
